<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

      <el-form-item label="日期">
        <el-date-picker
          v-model="queryParams.dvDate"
          size="small"
          style="width: 140px"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>



    <div>
        出库时，采用先进先出原则
    </div>
    <el-table v-loading="loading" :data="AttenceStaList" >
      <el-table-column label="供应商" align="center" prop="supplier" :show-overflow-tooltip="true" />
      <el-table-column label="商品名称" align="center" prop="goodsName" :show-overflow-tooltip="true" />
      <el-table-column label="剩余数量" align="center" prop="surplusNum" :show-overflow-tooltip="true" />
      <el-table-column label="累计数量" align="center" prop="total" :show-overflow-tooltip="true" />
      <el-table-column label="进出库明细" align="center"  :show-overflow-tooltip="true" >
          <template slot-scope="scope">
              <a @click="viewDetails(scope.row)" style="color:#0081f1">点击查看</a>
          </template>
      </el-table-column>
      <el-table-column label="操作" align="center" >
        <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="入库" placement="top" v-if="scope.row.isPut!=1">
                <el-button 
                        size="mini"
                        circle type="success"
                        icon="el-icon-download"
                        @click="handleSignUpdate(scope.row)"
                        v-hasPermi="['basedata:bclass:edit']"
                />
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="出库" placement="top" v-if="scope.row.isPut!=1">
                <el-button 
                        size="mini"
                        circle type="warning"
                        icon="el-icon-upload2"
                        @click="handleOutStock(scope.row)"
                />
            </el-tooltip>
        </template>
      </el-table-column>

    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="出入库明细" :visible="false">
        <el-table v-loading="detailLoading" :data="detailList">
        </el-table>
    </el-dialog>

    <el-dialog title="出库" :visible="outDialogVisible" width="30%">
        <el-form :model="formData" ref="formData" label-width="120px" :rules="rules">
            <el-form-item label="供应商">
                {{formData.supplier}}
            </el-form-item>
            <el-form-item label="物品名称">
                {{formData.goodsName}}
            </el-form-item>
            <el-form-item label="当前库存">
                <span style="color:#42e740">{{formData.surplusNum}}</span>
                {{getUnit(formData.goodsUnit)}}
            </el-form-item>
            <el-form-item label="出库数量">
                <el-input-number v-model="formData.inOutNumber" :min="1" :max="1000" label="出库数量"></el-input-number>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button  type="primary" @click="submitGoodsOutStock">确认出库</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>

  </div>
</template>



<script>
  import { getStockPageList } from "@/api/canteen/stock";
  export default {
    name: "stock",
    data(){
      return{
        serviceEnvPath:process.env.VUE_APP_BASE_API,
        // 遮罩层
        loading: true,
        outDialogVisible:false,
        detailLoading:false,
        // 总条数
        total: 0,
        AttenceStaList: [],
        detailList:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        formData:{
            supplier:undefined,
            goodsName:undefined,
            surplusNum:undefined,
            inOutNumber:undefined
        },
        goodsUnitList:[],
        rules:{}
        
      }
    },
    components:{
      // bargraph
    },
    created() {
        this.getDicts("goods_unit").then(response => {
            this.goodsUnitList = response.data;
        });
        this.getList();
    },
    methods: {
        getUnit(unit){
            //获取物品单位
            for(let i=0;i<this.goodsUnitList.length;i++){
                if(unit==this.goodsUnitList[i].dictValue){
                    return this.goodsUnitList[i].dictLabel
                }
            }
        },
      /** 查询任务量列表 */
      getList() {
        this.loading = true;
        getStockPageList(this.queryParams).then(response => {
            this.AttenceStaList = response.data.list;
            this.total = response.data.total;
            this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.outDialogVisible =false
        this.formData={}
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      viewDetails(row){
          //查看明细
      },
      handleOutStock(row){
          this.outDialogVisible =true
          this.formData = row
      },
      submitGoodsOutStock(){
          //提交出库

      }
    }
  }
</script>
